<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/layui/lib/layui-v2.5.5/css/layui.css"
          media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/layui/css/public.css" media="all">
    <style>
        .bordernoone{
            border: none;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">企业名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="e_name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn"><i
                                    class="layui-icon layui-icon-search"></i>搜索
                            </button>
                            <button type="reset" class="layui-btn layui-btn-warm"><i
                                    class="layui-icon layui-icon-refresh-1"></i>重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">审核</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

        <%-- 添加和修改窗口 --%>
        <div style="display: none;padding: 5px" id="addOrUpdateWindow">
            <form class="layui-form" style="width:90%;" id="dataFrm" lay-filter="dataFrm">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号状态</label>
                    <div class="layui-input-inline">
                        <select name="e_state">
                            <option value="" selected="">审核中</option>
                            <option value="通过">通过</option>
                            <option value="不通过">不通过</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号ID</label>
                    <div class="layui-input-block">
                        <%-- 隐藏域 --%>
                            <input type="text" name="e_id" lay-verify="required"  class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">企业类型</label>
                    <div class="layui-input-block">
                        <%-- 隐藏域 --%>
                        <input type="text" name="e_type" lay-verify="required"  class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_name" lay-verify="required" class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_address" class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">企业创始人</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_principal" class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_phone" class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_email" class="bordernoone layui-input" readonly="readonly">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">企业简介</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea bordernoone" name="e_intro" id="content" readonly="readonly"></textarea>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">企业文化</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea bordernoone" name="e_culture" id="content" readonly="readonly" style="margin-top: 20px;"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-row layui-col-xs12">
                        <div class="layui-input-block" style="text-align: center;">
                            <button type="button" class="layui-btn" lay-submit lay-filter="doSubmit"><span
                                    class="layui-icon layui-icon-add-1"></span>提交
                            </button>
                        </div>
                    </div>
            </form>
        </div>


    </div>
</div>
<script src="${pageContext.request.contextPath}/statics/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '${pageContext.request.contextPath}/admin/user/enterprise/list?check=1',
            toolbar: '#toolbarDemo',

            cols: [[
                {type: "checkbox", width: 50},
                {field: 'e_id', width: 120, title: '登录账号', align: 'center', sort: true},
                {field: 'e_name', minWidth: 120, title: '名称', align: 'center', sort: true},
                {field: 'e_type', minWidth: 120, title: '类型', align: 'center', sort: true},
                {field: 'e_principal', minWidth: 120, title: '创建人', align: 'center'},
                {field: 'e_state', minWidth: 120, title: '状态', align: 'center'},
                {title: '操作', minWidth: 120, toolbar: '#currentTableBar', align: "center"}
            ]],
            page: true,
            done: function (res, curr, count) {
                //判断当前页码是否是大于1并且当前页的数据量为0
                if (curr > 1 && res.data.length == 0) {
                    var pageValue = curr - 1;
                    //刷新数据表格的数据
                    tableIns.reload({
                        page: {curr: pageValue}
                    });
                }
            }

        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                mainIndex = layer.open({
                    type: 1,//打开类型
                    title: "添加企业信息",//窗口标题
                    area: ["800px", "400px"],//窗口宽高
                    content: $("#addOrUpdateWindow"),//引用的内容窗口
                    success: function () {
                        //清空表单数据
                        $("#dataFrm")[0].reset();
                        //添加的提交请求
                        url = "/admin/user/enterprise/addEnterprise";

                    }
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        //监听表单提交事件
        form.on("submit(doSubmit)", function (data) {
            $.post(url, data.field, function (result) {
                if (result.success) {
                    //刷新数据表格
                    tableIns.reload();
                    //关闭窗口
                    layer.close(mainIndex);
                }
                //提示信息
                layer.msg(result.message);
            }, "json");
            //禁止页面刷新
            return false;
        });



        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                mainIndex = layer.open({
                    type: 1,//打开类型
                    title: "修改企业账号",//窗口标题
                    area: ["800px", "400px"],//窗口宽高
                    content: $("#addOrUpdateWindow"),//引用的内容窗口
                    success: function () {
                        //表单数据回显
                        form.val("dataFrm", data);//参数1：lay-filter值  参数2：回显的数据
                        //修改的提交请求
                        url = "/admin/user/enterprise/updateEnterprise";
                    }
                });
            } else if (obj.event === 'delete') {
                //判断当前企业下是否存在真正招聘的工作
                $.get("/admin/user/enterprise/checkEnterpriseHasEmployment", {"e_id": data.e_id}, function (result) {
                    if (result.exist) {
                        //提示无法删除
                        layer.msg(result.message);
                    } else {
                        //提示用户是否删除该企业账号
                        layer.confirm("确定要删除[<font color='red'>" + data.e_name + "</font>]吗", {
                            icon: 3,
                            title: '提示'
                        }, function (index) {
                            //发送ajax请求进行删除
                            $.post("/admin/user/enterprise/deleteById", {"e_id": data.e_id}, function (result) {
                                if (result.success) {
                                    //刷新数据表格
                                    tableIns.reload();
                                }
                                //提示
                                layer.msg(result.message);
                            }, "json");

                            layer.close(index);
                        });
                    }
                }, "json");

            }
        });


        //查询企业类型下拉列表
        $.get("/admin/Type/findEnterpriseTypeAll",function(result){
            var html = "";
            for (var i = 0; i < result.length; i++) {
                html +="<option value='"+result[i].name+"'>"+result[i].name+"</option>"
            }
            //将网页代码追加到下拉列表中
            $("[name='e_type']").append(html);
            //重新渲染下拉列表
            form.render("select");
        },"json");
    });
</script>

</body>
</html>
